package com.bike.util;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

public class TimeTag extends TagSupport {

	/**
	 * ddd
	 */
	private static final long serialVersionUID = 1L;
	private String timelong;
	private int timeint;
	
	private String action;

	public int doEndTag() throws JspException {
		// TODO 自动生成方法存根
		timeint=Integer.parseInt(timelong);
		if (timeint > 0) {
			JspWriter out = pageContext.getOut();
			try {
				String str = String.valueOf(timeint*1000L);
				Date dd = new Date(Long.parseLong(str));
				SimpleDateFormat sdf = new SimpleDateFormat(
						"yyyy-MM-dd HH:mm:ss");
				String strtime = sdf.format(dd);

				if ("all".equals(action)) {
				} else if ("10".equals(action)) {
					strtime = strtime.substring(0, 10);
				} else if ("13".equals(action)) {
					strtime = strtime.substring(0, 13);
				} else if ("16".equals(action)) {
					strtime = strtime.substring(0, 16);
				}  else if ("19".equals(action)) {
					strtime = strtime.substring(0, 19);
				} else if ("7".equals(action)) {
					strtime = strtime.substring(0, 7);
				} else {
					strtime = strtime.substring(5, 10);
				}

				out.print(strtime);
			} catch (Exception e) {
				// TODO 自动生成 catch �?
				System.out.print(e.getMessage());
			}

		}

		return super.doEndTag();
	}

	public String getAction() {
		return action;
	}

	public void setAction(String action) {
		this.action = action==null?"":action;
	}

	public static long getSerialVersionUID() {
		return serialVersionUID;
	}

	public void setTimelong(String timelong) {
		this.timelong = timelong==null?"":timelong;
		this.timelong = this.timelong.equals("")?"0":timelong;
	}

	
}